import { _decorator, Component } from 'cc';
import { EvolutionNode, EvolutionNodeConfig } from './EvolutionNode';

/**
 * 进化树基类
 */
export abstract class BaseEvolutionTree extends Component {
    protected evolutionNodes: Map<string, EvolutionNode> = new Map();
    protected currentStage: string = '';

    protected addEvolutionNode(id: string, config: EvolutionNodeConfig) {
        const node = new EvolutionNode(id, config);
        this.evolutionNodes.set(id, node);
    }

    protected applyEvolutionEffects(node: EvolutionNode) {
        // 应用属性效果
        const character = this.getComponent('CharacterStats') as CharacterStats;
        if (character) {
            for (const [stat, value] of Object.entries(node.effects)) {
                character.modifyStat(stat, value);
            }
        }

        // 解锁技能
        const skillManager = this.getComponent('SkillManager') as SkillManager;
        if (skillManager) {
            node.skills.forEach(skillId => {
                skillManager.unlockSkill(skillId);
            });
        }
    }
}

// 添加必要的接口
interface CharacterStats extends Component {
    modifyStat(stat: string, value: number): void;
}

interface SkillManager extends Component {
    unlockSkill(skillId: string): void;
} 